<script>
export default {
  globalData: {
    StatusBar: null, //导航栏高度
    CustomBar: null, //导航栏高度
    phoneHeight: null, //手机高度
  },
  onLaunch: function () {
    console.log("App Launch");
    uni.hideTabBar();

    uni.getLocation({
      type: "gcj02",
      success: (res) => {
        let obj = uni.getStorageSync("location");
        if (obj) {
          let a = this.$util.getDistance(
            obj.latitude,
            obj.longitude,
            res.latitude,
            res.longitude
          );
          if (a > 20) {
            uni.removeStorageSync("store");
          }
        }
        uni.setStorage({
          key: "location",
          data: {
            latitude: res.latitude,
            longitude: res.longitude,
          },
          success: () => {
            // 触发全局事件通知location变化
            uni.$emit("storageChange", "location");
          },
        });
      },
    });
  },
  onShow: function () {
    console.log("App Show");
    // 设备信息
    var _this = this;
    uni.getSystemInfo({
      success: function (e) {
        console.log("设备信息", e);

        // #ifdef MP-WEIXIN
        _this.globalData.phoneHeight = e.windowHeight; //获取设备可用屏幕总高度
        _this.globalData.StatusBar = e.statusBarHeight;
        let custom = uni.getMenuButtonBoundingClientRect();
        _this.globalData.Custom = custom;
        _this.globalData.CustomBar =
          custom.bottom + custom.top - e.statusBarHeight;
        // #endif
      },
    });

    // 小程序版本更新
    // #ifdef MP
    const updateManager = uni.getUpdateManager();
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
    });

    updateManager.onUpdateReady(function (res) {
      uni.showModal({
        title: "更新提示",
        content: "新版本已经准备好，是否重启应用？",
        success(res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate();
          }
        },
      });
    });

    updateManager.onUpdateFailed(function (res) {
      // 新的版本下载失败
    });
    // #endif
  },
  onHide: function () {
    console.log("App Hide");
  },
};
</script>

<style lang="scss">
/*每个页面公共css */
@import "uview-ui/index.scss";
@import "./common/css/main.scss";
@import "./common/css/common.scss";
@import "./common/css/base.scss";
@import "./common/css/layout.scss";
@import "./common/css/index.scss";
</style>
